/*
 * GY80.h
 *
 *  Created on: 02-11-2012
 *      Author: Maciej
 */

#ifndef GY80_H_
#define GY80_H_


/// /// /// /// L3G
#define L3G_ADDR 0x69

#define L3G_WHO_AM_I      0x0F
#define L3G_I_AM      	  0xD3

#define L3G_CTRL_REG1     0x20
#define L3G_CTRL_REG2     0x21
#define L3G_CTRL_REG3     0x22
#define L3G_CTRL_REG4     0x23
#define L3G_CTRL_REG5     0x24
#define L3G_REFERENCE     0x25
#define L3G_OUT_TEMP      0x26
#define L3G_STATUS_REG    0x27

#define L3G_OUT_X_L       0x28
#define L3G_OUT_X_H       0x29
#define L3G_OUT_Y_L       0x2A
#define L3G_OUT_Y_H       0x2B
#define L3G_OUT_Z_L       0x2C
#define L3G_OUT_Z_H       0x2D

#define L3G_FIFO_CTRL_REG 0x2E
#define L3G_FIFO_SRC_REG  0x2F

#define L3G_INT1_CFG      0x30
#define L3G_INT1_SRC      0x31
#define L3G_INT1_THS_XH   0x32
#define L3G_INT1_THS_XL   0x33
#define L3G_INT1_THS_YH   0x34
#define L3G_INT1_THS_YL   0x35
#define L3G_INT1_THS_ZH   0x36
#define L3G_INT1_THS_ZL   0x37
#define L3G_INT1_DURATION 0x38


/// /// /// /// ADX
#define ADX_ADDR          0x53

#define ADX_DEVID_REG     0x00
#define ADX_DEVID         0xE5

#define ADX_TAP_TRESH_REG 0x1D

#define ADX_OFSX_REG      0x1E
#define ADX_OFSY_REG      0x1F
#define ADX_OFSZ_REG      0x20

#define ADX_BW_RATE_REG   0x2C
#define ADX_POWER_CTL_REG  0x2D
#define ADX_DATA_FORMAT_REG 0x31

#define ADX_X_REG    0x32
#define ADX_Y_REG    0x34
#define ADX_Z_REG    0x36

#define ADX_POWER_CTL_MEAS_BIT  3
#define ADX_DATA_FORMAT_FULL_RES_BIT  3


#define ADX_BW_1600 	0xF // 1111
#define ADX_BW_800  	0xE // 1110
#define ADX_BW_400  	0xD // 1101
#define ADX_BW_200  	0xC // 1100
#define ADX_BW_100 	 	0xB // 1011
#define ADX_BW_50   	0xA // 1010
#define ADX_BW_25   	0x9 // 1001
#define ADX_BW_12   	0x8 // 1000
#define ADX_BW_6    	0x7 // 0111
#define ADX_BW_3    	0x6 // 0110


/// /// /// /// HMC
#define HMC_ADDR 		0x1E

#define HMC_A_REG 		0x00
#define HMC_B_REG 		0x01
#define HMC_MODE_REG 	0x02
#define HMC_X_REG 		0x03
#define HMC_Z_REG 		0x05
#define HMC_Y_REG 		0x07

#define HMC_ID_REG		10
#define HMC_ID			0x48

/// /// /// /// BMP
#define BMP_ADDR 0x77

#define BMP_CHIP_ID_REG		0xD0
#define BMP_CHIP_ID			0x55

#define BMP_VERSION_REG			0xD1

#define BMP_CTRL_MEAS_REG		0xF4
#define BMP_ADC_OUT_MSB_REG		0xF6
#define BMP_ADC_OUT_LSB_REG		0xF7


// BMP085 Modes
#define BMP_MODE_ULTRA_LOW_POWER    0 //oversampling=0, internalsamples=1, maxconvtimepressure=4.5ms, avgcurrent=3uA, RMSnoise_hPA=0.06, RMSnoise_m=0.5
#define BMP_MODE_STANDARD           1 //oversampling=1, internalsamples=2, maxconvtimepressure=7.5ms, avgcurrent=5uA, RMSnoise_hPA=0.05, RMSnoise_m=0.4
#define BMP_MODE_HIGHRES            2 //oversampling=2, internalsamples=4, maxconvtimepressure=13.5ms, avgcurrent=7uA, RMSnoise_hPA=0.04, RMSnoise_m=0.3
#define BMP_MODE_ULTRA_HIGHRES      3 //oversampling=3, internalsamples=8, maxconvtimepressure=25.5ms, avgcurrent=12uA, RMSnoise_hPA=0.03, RMSnoise_m=0.25
                  // "Sampling rate can be increased to 128 samples per second (standard mode) for
                  // dynamic measurement.In this case it is sufficient to measure temperature only
                  // once per second and to use this value for all pressure measurements during period."
                  // (from BMP085 datasheet Rev1.2 page 10).
                  // To use dynamic measurement set AUTO_UPDATE_TEMPERATURE to false and
                  // call calcTrueTemperature() from your code.
// Control register
#define BMP_TEMPERATURE        0x2E
#define BMP_PRESSURE           0x34

#define BMP_TEMPERATURE_REG	   0xF6
#define BMP_PRESSURE_REG	   0xF6


//Other
#define BMP_MSLP                    1013.25          // Mean Sea Level Pressure = 1013.25 hPA





struct sensorStruct
{
	float aX;
	float aY;
	float aZ;
	float gX;
	float gY;
	float gZ;
	float mX;
	float mY;
	float mZ;
	float Pressure;
	float Temperature;
} ;

typedef struct sensorStruct sSensors;


void GY80_init(sSensors* sensors);

void GY80_Update(sSensors* sensors);

float GY80_ReadAngleAccZX(sSensors* sensors);



#endif /* GY80_H_ */
